﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Entities;
using System.ComponentModel.Composition;

namespace WebUI
{
    [Export(typeof(ISessionHelper))]
    public class SessionHelper : ISessionHelper
    {
        const string BOT_SESSION_KEY = "Bot";
        const string MaxStepReached_SESSION_KEY = "MaxStepReached";
        const string CurrentStep_SESSION_KEY = "CurrentStep";
        const string FILTER = "Filter";
        const string SORTDIRECTIONDESC = "SortDirectionDesc";
        const string SORTCOLUMN = "SortColumn";

        #region ISessionHelper

        BOT ISessionHelper.Bot
        {
            get
            {
                if (HttpContext.Current.Session[BOT_SESSION_KEY] == null)
                {
                    HttpContext.Current.Session[BOT_SESSION_KEY] = new BOT();
                }

                return HttpContext.Current.Session[BOT_SESSION_KEY] as BOT;
            }
            set
            {
                HttpContext.Current.Session[BOT_SESSION_KEY] = value;
            }
        }

        int ISessionHelper.MaxStepReached
        {
            get
            {
                if (HttpContext.Current.Session[MaxStepReached_SESSION_KEY] == null)
                {
                    HttpContext.Current.Session[MaxStepReached_SESSION_KEY] = 0;
                }

                return Convert.ToInt32(HttpContext.Current.Session[MaxStepReached_SESSION_KEY]);
            }
            set
            {
                HttpContext.Current.Session[MaxStepReached_SESSION_KEY] = value;
            }
        }

        string ISessionHelper.CurrentStep
        {
            get
            {
                if (HttpContext.Current.Session[CurrentStep_SESSION_KEY] == null)
                {
                    HttpContext.Current.Session[CurrentStep_SESSION_KEY] = "";
                }

                return HttpContext.Current.Session[CurrentStep_SESSION_KEY].ToString();
            }
            set
            {
                HttpContext.Current.Session[CurrentStep_SESSION_KEY] = value;
            }
        }

        FilterOperations ISessionHelper.Filter
        {
            get
            {
                return HttpContext.Current.Session[FILTER] as FilterOperations;
            }
            set
            {
                HttpContext.Current.Session[CurrentStep_SESSION_KEY] = value;
            }
        }

        bool ISessionHelper.SortDirectionDesc
        {
            get
            {
                return Convert.ToBoolean(HttpContext.Current.Session[SORTDIRECTIONDESC]);
            }
            set
            {
                HttpContext.Current.Session[SORTDIRECTIONDESC] = value;
            }
        }

        string ISessionHelper.SortColumn
        {
            get
            {
                return HttpContext.Current.Session[SORTDIRECTIONDESC] as string;
            }
            set
            {
                HttpContext.Current.Session[SORTDIRECTIONDESC] = value;
            }
        }

        #endregion
    }
}